package main

import (
	"context"
	"fmt"
	"github.com/micro/go-micro/v2"
	"github.com/micro/go-micro/v2/client"
	"go-micro/src/Course"
	"go-micro/src/Users"
	"log"
)

type UserService struct {
	client client.Client
}

func NewUserService(client client.Client) *UserService {

	return &UserService{client: client}
}

func (this *UserService) Test(ctx context.Context, req *Users.UserRequest, rsp *Users.UserResponse) error {
	fmt.Println(req.Id)
	rsp.Ret = "users " + req.Id

	course := Course.NewCourseService("go.micro.api.haojin.course", this.client)

	res, _ := course.LostForTop(ctx, &Course.CourseRequest{Size: 333})
	fmt.Println(res)
	return nil
}

func main() {
	service := micro.NewService(micro.Name("go.micro.api.haojin.user"))
	service.Init()

	err := Users.RegisterUserServiceHandler(service.Server(), NewUserService(service.Client()))
	if err != nil {
		log.Fatal(err)
	}

	if err = service.Run(); err != nil {
		fmt.Println(err)
	}
}
